dojo.provide("uws.drawing.classdiagram.Generalization");
dojo.require('uws.drawing.Connection');

dojo.declare('uws.drawing.classdiagram.Generalization', uws.drawing.Connection,{
	constructor: function(id, surface, shape1, shape1_dir, shape2, shape2_dir, stereotype){
		this.umltype = "generalization2";
		this.stereotype_shape = this.group.createText({
			text: stereotype,
			x:((this.x2+this.x1)/2),
			y:(((this.y2+this.y1)/2)-5),
			align:"middle"
		}).setFill("black").setFont(defaultFont);
		
		this.shapeCon = this.group.createLine({
			x1:this.x1,
			y1:this.y1,
			x2:this.x2,
			y2:this.y2
		}).setStroke({color: "black",width:2});
		
		var arrowPoints = this.getArrowCoordinates();
		
		this.shapeCon2 = this.group.createPolyline([
			{x: this.x2, y:this.y2},
			{x: arrowPoints[1].x, y:arrowPoints[1].y},
			{x: arrowPoints[2].x, y:arrowPoints[2].y},
			{x: this.x2, y: this.y2},
		]).setStroke({color: "black"}).setFill({color:"white"});
		
		this.shape1_monitor = dojo.connect(shape1.shape_moveable,"onMoving",this,function(mover,shift){
			if (mover.shape.matrix == null) {
				mover.shape.matrix = {
					dx: 0,
					dy: 0
				};
			}
			
			this.shapeCon.setShape({
				x1:(this.con_x1 + mover.shape.matrix.dx),
				y1:(this.con_y1 + mover.shape.matrix.dy),
				x2:this.x2,
				y2:this.y2
			}).setStroke({color: "black",width:2});
			
			this.x1=(this.con_x1 + mover.shape.matrix.dx);
			this.y1=(this.con_y1 + mover.shape.matrix.dy);
			
			var arrowPoints = this.getArrowCoordinates();
			
			this.shapeCon2.setShape([
				{x: this.x2, y:this.y2},
				{x: arrowPoints[1].x, y:arrowPoints[1].y},
				{x: arrowPoints[2].x, y:arrowPoints[2].y},
				{x: this.x2, y: this.y2},
			]).setStroke({color: "black"}).setFill({color:"white"});
			
			this.shapeCon.moveToBack();
			this.stereotype_shape.setShape({
				x:((this.x2+this.x1)/2),
				y:(((this.y2+this.y1)/2)-5)
			});
		});
		
		this.shape2_monitor = dojo.connect(shape2.shape_moveable,"onMoving",this,function(mover,shift){
			if (mover.shape.matrix == null) {
				mover.shape.matrix = {
					dx: 0,
					dy: 0
				};
			}
			this.shapeCon.setShape({
				x1:this.x1,
				y1:this.y1,
				x2:(this.con_x2 + mover.shape.matrix.dx),
				y2:(this.con_y2 + mover.shape.matrix.dy)
			}).setStroke({color: "black",width:2});
			
			this.x2=(this.con_x2 + mover.shape.matrix.dx);
			this.y2=(this.con_y2 + mover.shape.matrix.dy);
			
			var arrowPoints = this.getArrowCoordinates();
			
			this.shapeCon2.setShape([
				{x: this.x2, y:this.y2},
				{x: arrowPoints[1].x, y:arrowPoints[1].y},
				{x: arrowPoints[2].x, y:arrowPoints[2].y},
				{x: this.x2, y: this.y2},
			]).setStroke({color: "black"}).setFill({color:"white"});
			
			this.shapeCon.moveToBack();
			this.stereotype_shape.setShape({
				x:((this.x2+this.x1)/2),
				y:(((this.y2+this.y1)/2)-5)
			});
		});
	},
	applyProperties:function(properties){
		this.stereotype_shape.setShape({
			text: "<<"+properties.stereotype+">>",
			x:((this.x2+this.x1)/2),
			y:(((this.y2+this.y1)/2)-5),
			align:"middle"
		}).setFill("black").setFont(defaultFont);
	}
});